{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ab95667e",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-03T05:28:21.757008Z",
     "start_time": "2021-12-03T05:28:21.742140Z"
    }
   },
   "source": [
    "## 第二章课本案例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "43534e4d",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-03T05:28:55.923105Z",
     "start_time": "2021-12-03T05:28:55.918104Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a', 'e', 'i', 'o', 'u']\n",
    "word = \"Milliways\"\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        print(letter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "1352cd39",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-03T05:29:21.559443Z",
     "start_time": "2021-12-03T05:29:21.546452Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a', 'e', 'i', 'o', 'u']\n",
    "word = \"Milliways\"\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "for vowel in found:\n",
    "    print(vowel)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "bdb9f790",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-03T05:29:44.939541Z",
     "start_time": "2021-12-03T05:29:41.247107Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Provide a word to search for vowels: fhaILDGHlkghsKGH\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a', 'e', 'i', 'o', 'u']\n",
    "word = input(\"Provide a word to search for vowels: \")\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "for vowel in found:\n",
    "    print(vowel)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "cd462464",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-03T05:30:03.452297Z",
     "start_time": "2021-12-03T05:30:03.438293Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "['o', 'n', ' ', 't', 'a', 'p']\n",
      "on tap\n"
     ]
    }
   ],
   "source": [
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)\n",
    "\n",
    "for i in range(4):\n",
    "    plist.pop()\n",
    "plist.pop(0)\n",
    "plist.remove(\"'\")\n",
    "plist.extend([plist.pop(), plist.pop()])\n",
    "plist.insert(2, plist.pop(3))\n",
    "\n",
    "new_phrase = ''.join(plist)\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "3c78a0ab",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-03T05:30:46.452383Z",
     "start_time": "2021-12-03T05:30:46.437054Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "on tap\n"
     ]
    }
   ],
   "source": [
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)\n",
    "\n",
    "new_phrase = ''.join(plist[1:3])\n",
    "new_phrase = new_phrase + ''.join([plist[5], plist[4], plist[7], plist[6]])\n",
    "\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "81978d80",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-03T05:30:47.719725Z",
     "start_time": "2021-12-03T05:30:47.713718Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\t M\n",
      "\t a\n",
      "\t r\n",
      "\t v\n",
      "\t i\n",
      "\t n\n"
     ]
    }
   ],
   "source": [
    "paranoid_android = \"Marvin\"\n",
    "letters = list(paranoid_android)\n",
    "for char in letters:\n",
    "    print('\\t', char)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "bff3b737",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-03T05:30:50.185020Z",
     "start_time": "2021-12-03T05:30:50.169025Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\t M\n",
      "\t a\n",
      "\t r\n",
      "\t v\n",
      "\t i\n",
      "\t n\n",
      "\n",
      "\t\t A\n",
      "\t\t n\n",
      "\t\t d\n",
      "\t\t r\n",
      "\t\t o\n",
      "\t\t i\n",
      "\t\t d\n",
      "\n",
      "\t\t\t P\n",
      "\t\t\t a\n",
      "\t\t\t r\n",
      "\t\t\t a\n",
      "\t\t\t n\n",
      "\t\t\t o\n",
      "\t\t\t i\n",
      "\t\t\t d\n"
     ]
    }
   ],
   "source": [
    "paranoid_android = \"Marvin, the Paranoid Android\"\n",
    "letters = list(paranoid_android)\n",
    "for char in letters[:6]:\n",
    "    print('\\t', char)\n",
    "print()\n",
    "for char in letters[-7:]:\n",
    "    print('\\t'*2, char)\n",
    "print()\n",
    "for char in letters[12:20]:\n",
    "    print('\\t'*3, char)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f9ee842f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
